package com.wizo.csb.generator;

import java.util.Random;

public class BoundIntegerGenerator extends IntegerGenerator{
	
	Random _random;
	int _lowerBound, _upperBound, _interval;
	int _validInteger;
	/**
	 * Create a generator that will return integers from the interval [_lowerBound, _upperBound] inclusive
	 * randomly if _isRandom is true, otherwise orderly
	 * @param lb the lower bound (inclusive) of generated values
	 * @param ub the upper bound (inclusive) of generated values
	 */
	public BoundIntegerGenerator(int lb, int ub){
		_random = new Random();
		_lowerBound = lb;
		_upperBound = ub;
		_interval = _upperBound-_lowerBound+1;
		_validInteger = _interval;
		_lastInt = lb-1;
		
	}
	
	@Override
	public synchronized int nextInteger(){
		int next = -1;
		next = _random.nextInt(_interval)+_lowerBound;
		setLastInt(next);
		
		return next;
	}
}
